package org.smr.ministore.micro.client;

import feign.hystrix.FallbackFactory;
import org.blade.utils.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smr.ministore.entities.Dictionary;
import org.smr.ministore.entities.DictionaryGroupQueryVO;
import org.smr.ministore.entities.DictionaryOrgan;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;


@Component
public class HystrixDictionaryClientFactory implements FallbackFactory<FeignDictionaryMicroServiceClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixDictionaryClientFactory.class);

    @Override
    public FeignDictionaryMicroServiceClient create(Throwable cause) {
        HystrixDictionaryClientFactory.LOGGER.info("fallback; reason was: {}", cause.getMessage());

        return new FeignDictionaryMicroServiceClient() {


            @Override
            public int batchSave(List<Dictionary> entities) {
                return -1;
            }

            @Override
            public int save(Dictionary entity) {
                return -1;
            }

            @Override
            public int updateById(Dictionary id) {
                return -1;
            }

            @Override
            public Dictionary queryById(Long id) {
                Dictionary d
                        = new Dictionary();
                d.setId(-1L);
                return d;
            }

            @Override
            public int deleteById(Long id) {
                return -1;
            }

            @Override
            public Pager<Dictionary> paginate(Dictionary entity, Long pageSize, Long pageNum) {
                Pager<Dictionary> pager = new Pager();
                pager.setTotalCount(-1l);
                pager.setPageSize(-1l);
                pager.setCurrentPage(-1L);
                return pager;
            }

            @Override
            public List<Dictionary> getDictionaryGroup(DictionaryGroupQueryVO query) {
                Dictionary d = new Dictionary();
                d.setId(-1L);
                return Arrays.asList(d);
            }

            @Override
            public List<Dictionary> getDictionaryGroup(int sys, String bigType, Long organId, String organPath) {
                Dictionary d = new Dictionary();
                d.setId(-1L);
                return Arrays.asList(d);
            }

            public List<Map<String, Object>> getReferencedDictionaryList(int sys, Long organId, String bigType, Long originId) {
                return Collections.emptyList();
            }

            @Override
            public List<Map<String, Object>> getReferencedDictionaryList(Map<String, Object> params) {
                return Collections.emptyList();
            }

            @Override
            public Pager<Dictionary> getOrganReferencedDictionaryPagination(Dictionary entity, Long pageSize, Long pageNum) {
                Pager<Dictionary> pager = new Pager();
                pager.setTotalCount(-1l);
                pager.setPageSize(-1l);
                pager.setCurrentPage(-1L);
                return pager;
            }

            @Override
            public List<Dictionary> getOrganReferencedDictionary(Dictionary entity) {
                Dictionary d = new Dictionary();
                d.setId(-1L);
                return Arrays.asList(d);
            }
        };//Return end
    }
}